package com.muqi.server.controller;

import com.muqi.server.common.response.ResponseClass;

import com.muqi.server.domain.bo.GenderBO;
import com.muqi.server.domain.vo.*;
import com.muqi.server.service.GenderService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin(origins = "*",allowedHeaders = "*", maxAge = 3600)
@RestController
@RequestMapping("/Gender")
@RequiredArgsConstructor
public class GenderController {

    @Autowired
    private final GenderService genderService;

    @GetMapping("/getGenderCount")
    public ResponseEntity<?> getGenderCount() {
            GenderBO genderBO = genderService.getGender();
            GenderVO genderVO = new GenderVO();

            genderVO.setMaleCount(genderBO.getMaleCount());
            genderVO.setFemaleCount(genderBO.getFemaleCount());
            genderVO.setSumCount(genderBO.getMaleCount() + genderBO.getFemaleCount());

            return ResponseEntity.ok().body(new ResponseClass(200, genderVO, "获取成功"));
    }


    @GetMapping("/getAllClassGender")
    public ResponseEntity<?> getAllClassGender() {
        List<ClassGenderVO> genderVoList = genderService.getAllClassGender().stream()
                .map(genderBO -> {
                    ClassGenderVO classGenderVO = new ClassGenderVO();
                    classGenderVO.setClassId(genderBO.getClassId());
                    classGenderVO.setMaleCount(genderBO.getMaleCount());
                    classGenderVO.setFemaleCount(genderBO.getFemaleCount());
                    classGenderVO.setSumCount(genderBO.getMaleCount() + genderBO.getFemaleCount());
                    return classGenderVO;
                })
                .toList();


        return ResponseEntity.ok().body(new ResponseClass(200, genderVoList, "获取成功"));
    }

    @GetMapping("/getStatusGender")
    public ResponseEntity<?> getStatusGender() {
        List<StatusGenderVO> statusGenderVOList = genderService.getAllStatusGender().stream()
                .map(statusGenderBO -> {
                    StatusGenderVO statusGenderVO = new StatusGenderVO();
                    statusGenderVO.setStatus(statusGenderBO.getStatus());
                    statusGenderVO.setMaleCount(statusGenderBO.getMaleCount());
                    statusGenderVO.setFemaleCount(statusGenderBO.getFemaleCount());
                    statusGenderVO.setSumCount(statusGenderBO.getMaleCount() + statusGenderBO.getFemaleCount());
                    return statusGenderVO;
                })
                .toList();
        return ResponseEntity.ok().body(new ResponseClass(200, statusGenderVOList, "获取成功"));
    }

    @GetMapping("/getSemesterGender")
    public ResponseEntity<?> getSemesterGender() {
        List<SemesterGenderVO> semesterGenderVOList = genderService.getAllSemesterGender().stream()
                .map(semesterGenderBO -> {
                    SemesterGenderVO semesterGenderVO = new SemesterGenderVO();
                    semesterGenderVO.setSemester(semesterGenderBO.getSemester());
                    semesterGenderVO.setMaleCount(semesterGenderBO.getMaleCount());
                    semesterGenderVO.setFemaleCount(semesterGenderBO.getFemaleCount());
                    semesterGenderVO.setSumCount(semesterGenderBO.getMaleCount() + semesterGenderBO.getFemaleCount());
                    return semesterGenderVO;
                })
                .toList();
        return ResponseEntity.ok().body(new ResponseClass(200, semesterGenderVOList, "获取成功"));
    }

    @GetMapping("/getSemesterClassGender")
    public ResponseEntity<?> getSemesterClassGender() {
        List<SemesterClassGenderVO> semesterClassGenderVOList = genderService.getAllSemesterClassGender().stream()
                .map(semesterClassGenderBO -> {
                    SemesterClassGenderVO semesterClassGenderVO = new SemesterClassGenderVO();
                    semesterClassGenderVO.setSemester(semesterClassGenderBO.getSemester());
                    semesterClassGenderVO.setClassId(semesterClassGenderBO.getClassId());
                    semesterClassGenderVO.setMaleCount(semesterClassGenderBO.getMaleCount());
                    semesterClassGenderVO.setFemaleCount(semesterClassGenderBO.getFemaleCount());
                    semesterClassGenderVO.setSumCount(semesterClassGenderBO.getMaleCount() + semesterClassGenderBO.getFemaleCount());
                    return semesterClassGenderVO;
                })
                .toList();
        return ResponseEntity.ok().body(new ResponseClass(200, semesterClassGenderVOList, "获取成功"));
    }

}
